<template>
  <a-modal v-model="currentLogVisible" width="700px"  :footer="null" title="日志" @cancel="currentLogVisible = false">
    <a-table
      bordered
      :columns="columns"
      :rowKey="record => record.id"
      :data-source="logList"
      :pagination="pagination"
      :scroll="{ x: true }"
      @change="handleTableChange"
    >
    </a-table>
  </a-modal>
</template>
<script>
  import { storeVouLog } from '@/api/marketingCenter/storeCoupon.js'
  import { STable } from '@views/box/components'
  const columns = [
    {
      title: '时间',
      key: 'createTime',
      dataIndex: 'createTime'
    },
    {
      title: '行为',
      key: 'operateDesc',
      dataIndex: 'operateDesc'
    },
    {
      title: '操作人',
      key: 'operatorName',
      dataIndex: 'operatorName'
    }
  ]
export default {
  props: {
    logVisible: {
      type: Boolean,
      default: false
    }
  },
  components: {
    STable
  },
  data() {
    return {
      columns,
      pagination: {
        total: 0,
        current: 1,
        pageSize: 10,
        pageSizeOptions: ['10', '20', '30', '40'],
        showSizeChanger: true,
        showTotal: total => `共 ${total} 条记录`,
        itemRender: (current, type, originalElement) => {
          if (type === 'prev') {
            return <a>上一页</a>
          } else if (type === 'next') {
            return <a>下一页</a>
          }
          return originalElement
        }
      },
      id: '',
      logList: []
    }
  },
  computed: {
    currentLogVisible: {
      get () {
        return this.logVisible
      },
      set (val) {
        this.$emit('update:logVisible', val)
      }
    },
  },
  created() {
  },
  methods: {
    handleTableChange(pagination) {
      this.pagination = pagination
      this.getLog(this.id)
    },
    getLog(id, parent) {
      this.id = id
      if (parent) {
        this.pagination.current = 1
      }
      this.logList= []
      const {current, pageSize} = this.pagination
      const data = {
          actId: this.id,
          current: current,
          size: pageSize
      }
      storeVouLog(data).then(res => {
        if (res.code == 200) {
          const {records, total} = res.data
          this.logList = records || []
          this.pagination.total = total || 0
        } else {
          this.$message.warning(res.msg)
        }
      })
    },
  }
}
</script>
<style lang="less" scoped>
</style>
